// +----------------------------------------------------------------------
// | CmsWing [ 美业管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 psi All rights reserved.
// +----------------------------------------------------------------------
// | Author: huang <2374266244@qq.com>
// +----------------------------------------------------------------------
'use strict';
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  async saveIndexBannerAction() {
    const data = this.post();
    data.departmentid = this.userinfo.departmentid;
    const isexist = await this.model('or_weixin_config').where({departmentid: data.departmentid}).find();
    let res;
    if (!think.isEmpty(isexist)) {
      res = await this.model('or_weixin_config').where({departmentid: data.departmentid}).update(data);
    } else {
      res = await this.model('or_weixin_config').add(data);
    }
    return res ? this.success('编辑成功') : this.fail('编辑失败');
  }

  async getWeiXinConfigAction() {
    const res = await this.model('or_weixin_config').where({departmentid: this.userinfo.departmentid}).find();
    return this.json(res);
  }
}
